package com.ysstech.reportworld.enums;

import com.ysstech.common.enums.BaseEnum;
import com.ysstech.common.util.StringUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 基础数据表中需要按照大字段显示的
 *
 * @author lsl
 */
@Getter
@AllArgsConstructor
public enum ReportWorldDataBaseEnum implements BaseEnum<String> {
    REPORT_NORMAL("RW_DB_TC_REP_DATASET", "DATASET_SQL");

    private final String code;
    private final String desc;

    public static ReportWorldDataBaseEnum getEnum(String code) {
        return Arrays.stream(values()).filter(b -> Objects.equals(b.code, code)).findFirst().orElse(null);
    }

    public static String getEnumDesc(String code) {
        ReportWorldDataBaseEnum e = getEnum(code);
        return e != null ? e.desc : null;
    }

    /**
     * 判断当前配置的字段是否按照大字段显示
     *
     * @return
     */
    public static Boolean checkReportWorldDataBase(String tableName, String columName) {
        if (StringUtils.isBlank(tableName) || StringUtils.isBlank(columName)) {
            return false;
        }
        for (ReportWorldDataBaseEnum dataBaseEnum : ReportWorldDataBaseEnum.values()) {
            if (null == dataBaseEnum) {
                continue;
            }
            if (tableName.equals(dataBaseEnum.getCode()) && StringUtil.oneCase(columName, dataBaseEnum.getDesc())) {
                return true;
            }
        }
        return false;
    }
}
